package cn.itcast.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/*
删除数据
 */
public class JDBC_Demo2 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement statement = null;
        try {
            // 1.注册驱动
            Class.forName("com.mysql.jdbc.Driver");

            // 2.获取连接对象
            conn = DriverManager.getConnection("jdbc:mysql:///test");

            // 3.获取sql执行对象（本次练习insert）
            statement = conn.createStatement();

            // 4.执行sql
            // String sql = "insert into emp values(7758,null,null,null,null,null,null,null)";
            String sql = "delete from emp where empno = 7758";
            int i = statement.executeUpdate(sql);

            if(i>0){
                System.out.println("执行成功");
            }
            else{
                System.out.println("执行失败");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally{
            if(conn != null)
            {
                //资源释放
                try {
                    conn.close();
                    if(statement != null)
                    {
                        statement.close();
                    }
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }

            }
        }
    }


}
